package deconstruction.deconTable;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ContainerMerchant;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.Player;

public class PacketHandler implements IPacketHandler {

	private EntityPlayerMP playerEntity;

	@Override
	public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) {
	       playerEntity = (EntityPlayerMP) player;
		if ("DeconChannel".equals(packet.channel))
        {
            try
            {
                DataInputStream datainputstream = new DataInputStream(new ByteArrayInputStream(packet.data));
                int i = datainputstream.readInt();
                Container container = this.playerEntity.openContainer;

                if (container instanceof ContainerDeconstructionTable)
                {
                    ((ContainerDeconstructionTable)container).setCurrentRecipeIndex(i);
                }
            }
            catch (Exception exception2)
            {
                exception2.printStackTrace();
            }
        }
	        
	}
	

}